package com.enzoism.springboot.dive.scene1;

import com.enzoism.springboot.dive.common.AppConstants;
import com.enzoism.springboot.dive.common.CompareSortUtil;

import java.util.*;

public class Scene1Test {
    /**
     * 场景一：单字段排序（根据前端传递的字段进行排序）
     * Map传递格式：sortMap:{"sortField":"usrId","sortType":"desc"}
     */
    public static void main(String[] args) {
        List<Scene1Model> scene1Models = Scene1Test.initDataList();

        Map<String,String> sortMap = new HashMap<>();
        sortMap.put(AppConstants.ORDER_FIELD,AppConstants.ORDER_USR_NUM);
        sortMap.put(AppConstants.ORDER_TYPE,AppConstants.ORDER_TYPE_DESC);
        Scene1Model.setSortMap(ThreadLocal.withInitial(()->sortMap));
        Collections.sort(scene1Models);
        Scene1Model.unload();

        CompareSortUtil.printDataList(scene1Models);
    }


    public static List<Scene1Model> initDataList(){
        List<Scene1Model> dataList = new ArrayList<>();
        Scene1Model scene1Model1 = new Scene1Model("001", 010, 010);
        Scene1Model scene1Model2 = new Scene1Model("001", 010, 001);
        Scene1Model scene1Model3 = new Scene1Model("001", 101, 300);
        Scene1Model scene1Model4 = new Scene1Model("002", 31, 178);
        Scene1Model scene1Model5 = new Scene1Model("003", 51, 881);
        Scene1Model scene1Model6 = new Scene1Model("004", 61, 1);
        Scene1Model scene1Model7 = new Scene1Model("009", 178, 10);
        Scene1Model scene1Model8 = new Scene1Model("005", 13, 129);
        Scene1Model scene1Model9 = new Scene1Model("006", 100, 150);
        dataList.add(scene1Model1);
        dataList.add(scene1Model2);
        dataList.add(scene1Model3);
        dataList.add(scene1Model4);
        dataList.add(scene1Model5);
        dataList.add(scene1Model6);
        dataList.add(scene1Model7);
        dataList.add(scene1Model8);
        dataList.add(scene1Model9);
        return dataList;
    }
}
